using System.Drawing;
using Kaleida.ServiceMonitor.Model.Runtime;
using Kaleida.ServiceMonitor.Model.ScriptDirectives;
using NUnit.Framework;

namespace Kaleida.UnitTests.Model.Runtime
{
	[TestFixture]
    public class StateColourationStrategyTests
    {
        [Test]
        public void TestGetNotificationColourIsGreyWhenNotRunning()
        {
            var presentation = new StateColourationStrategy();
            Assert.AreEqual(Color.Gray, presentation.GetNotificationColour(new MockMonitorState {IsMonitoring = false}));
        }

        [Test]
        public void TestGetNotificationColourIsGreenWhenRunningAndNoErrors()
        {
            var state = new MockMonitorState {IsMonitoring = true};
            Assert.AreEqual(Color.LightGreen, new StateColourationStrategy().GetNotificationColour(state));
        }

        [Test]
        public void TestGetNotificationColourChangesAsErrorsAccumulate()
        {
            var presentation = new StateColourationStrategy();

            Assert.AreEqual(Color.Yellow, presentation.GetNotificationColour(new MockMonitorState { IsMonitoring = true, FailureCount = 1 }));
            Assert.AreEqual(Color.Orange, presentation.GetNotificationColour(new MockMonitorState { IsMonitoring = true, FailureCount = 2 }));
            Assert.AreEqual(Color.Orange, presentation.GetNotificationColour(new MockMonitorState { IsMonitoring = true, FailureCount = 9 }));
            Assert.AreEqual(Color.LightCoral, presentation.GetNotificationColour(new MockMonitorState { IsMonitoring = true, FailureCount = 10 }));
            Assert.AreEqual(Color.LightCoral, presentation.GetNotificationColour(new MockMonitorState { IsMonitoring = true, FailureCount = 99 }));
            Assert.AreEqual(Color.Crimson, presentation.GetNotificationColour(new MockMonitorState { IsMonitoring = true, FailureCount = 100 }));
            Assert.AreEqual(Color.Crimson, presentation.GetNotificationColour(new MockMonitorState { IsMonitoring = true, FailureCount = 1000 }));
        }

        [Test]
        public void TestDescription()
        {
            var presentation = new StateColourationStrategy();
            Assert.AreEqual("Not monitoring: Gray, 0 failures: LightGreen, 1 failure: Yellow, 2 to 9 failures: Orange, 10 to 99 failures: LightCoral, 100 or more failures: Crimson, otherwise White", presentation.Description);
        }

        [Test]
        public void TestParse()
        {
            var semicolonSeparated = StateColourationStrategy.Parse("0-1 failures green; 2-9 failures yellow; 9+ failures orange");
        	Assert.AreEqual("Not monitoring: Gray, 0 to 1 failures: Green, 2 to 9 failures: Yellow, 9 or more failures: Orange, otherwise White", semicolonSeparated.Description);

            var commaSeparated = StateColourationStrategy.Parse("0-1 failures green, 2-9 failures yellow, 9+ failures orange");
			Assert.AreEqual("Not monitoring: Gray, 0 to 1 failures: Green, 2 to 9 failures: Yellow, 9 or more failures: Orange, otherwise White", commaSeparated.Description);

            var mixedSeparators = StateColourationStrategy.Parse("0-1 failures green, 2-9 failures yellow; 9+ failures orange");
			Assert.AreEqual("Not monitoring: Gray, 0 to 1 failures: Green, 2 to 9 failures: Yellow, 9 or more failures: Orange, otherwise White", mixedSeparators.Description);

            var separatorAtEnd = StateColourationStrategy.Parse("0-1 failures green,");
			Assert.AreEqual("Not monitoring: Gray, 0 to 1 failures: Green, otherwise White", separatorAtEnd.Description);

			//#colours "0 failures: green, 1 failure yellow, 2-9 orange, 100+ failures crimson"
			//#colours "0-100ms 99th-percentile-duration blue, 100ms-0.5s cyan, 0.5s+ pink"
			//#colours "0-50% success-rate red, 50%-90% orange, 90-99% yellow,99-99.9% yellowgreen, 99.9%+ green"
        }
    }
}